package com.d3works.apps.baml.xml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;

@XmlType
public class ConditionalNode extends ProcessActionNode {

  @XmlAttribute(name = "expression")
  private String expression;

  @XmlAttribute(name = "expressionValue")
  private String expressionValue;

  public String getExpression() {
    return expression;
  }

  public String expressionValue() {
    return expressionValue;
  }

  @Override
  public String toCode(boolean dynamic) {

    if (expression == null) {
      return "";
    }

    StringBuilder codeBuilder = new StringBuilder();
    codeBuilder.append("\nif(" + expression + ") {");
    codeBuilder.append(super.toCode(dynamic));
    codeBuilder.append("\n}");

    return codeBuilder.toString();
  }
}
